<?php

/**
 * MVM_MALL 网上商店系统 统计文件
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-12 $
 * $Id: counter.php  www.mvmmall.com$
 * ---------------------------------------------
*/

// 前台部分
if(!defined('MVMMALL')){
    exit('Access Denied');
}
if($_SESSION['mvmmall_join'] != 'mvmmall') {
	$mvmmall_join             = 'mvmmall';
	$_SESSION['mvmmall_join'] = $mvmmall_join;
	// 全部前台部分
	$counter_list =  $db->get_one("SELECT * FROM `{$tablepre}counter_table` WHERE uid = '1'");
	if($counter_list['counter_regdate'] == $m_now_counter) {
		$query = "UPDATE {$tablepre}counter_table SET
                         counter_total = counter_total + 1,
                         counter_now   = counter_now + 1
                         WHERE uid     = '1'";
		$db->query($query);
	} else {
		if($counter_list['counter_max'] < $counter_list['counter_now'] ) { 
			$counter_list['counter_max'] = $counter_list['counter_now'] ; 
		}
		if($counter_list['counter_min'] > $counter_list['counter_now'] || $counter_list['counter_min'] == "0") { 
			$counter_list['counter_min'] = $counter_list['counter_now'] ; 
		}

		$query = "UPDATE `{$tablepre}counter_table` SET
                         counter_total     = counter_total + 1,
                         counter_max       = '$counter_list[counter_max]',
                         counter_min       = '$counter_list[counter_min]',
                         counter_yesterday = '$counter_list[counter_now]',
                         counter_now       = 1,
                         counter_regdate   = '$m_now_counter'
                         WHERE uid         = 1";
		$db->query($query);
	}

	// 按时间别，输入的部分
	$time_list =  $db->get_one("SELECT * FROM `{$tablepre}time_table` WHERE time_regdate = '$m_now_counter'");
	$time_hour = date("H",$m_now_time);
	$time_name = "time_hit_".$time_hour;

	if($time_list['time_regdate']) {
		$db->query("UPDATE `{$tablepre}time_table` SET $time_name = $time_name + 1 WHERE time_regdate = '$m_now_counter'");
	} else {
		$db->query("INSERT INTO `{$tablepre}time_table` SET $time_name   =  '1',time_regdate = '$m_now_counter'");
	}

	// referer输入部分
	$referer_url      = parse_url($_SERVER['HTTP_REFERER']);
	if(!$referer_url['host']) {
		$referer_name = "NOT_REPERER";
	} else {
		$referer_name = eregi_replace("www.","",$referer_url[host]);
		$referer_name = eregi_replace(" ","",$referer_name);
	}
	$referer_list     =  $db->get_one("SELECT * FROM `{$tablepre}referer_table` WHERE referer = '$referer_name'");
	if($referer_list['referer']) {
		$db->query("UPDATE {$tablepre}referer_table SET referer_hit = referer_hit + 1 WHERE referer = '$referer_name'");
	} else {
		$db->query("INSERT INTO `{$tablepre}referer_table` SET referer  = '$referer_name', referer_hit = '1'");
	}
}
